package cn.jiangjiesheng.bootstrap.fileport.domain.doc;


import cn.jiangjiesheng.bootstrap.fileport.domain.doc.generator.PdfCov;
import cn.jiangjiesheng.bootstrap.fileport.domain.doc.generator.TplWord;
import cn.jiangjiesheng.bootstrap.fileport.domain.doc.model.ReportDataModel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.io.InputStream;

/**
 * Created by dev@jiangjiesheng.cn on 2021/3/17  <br/>
 */
@Primary
@Slf4j
@Service
public class ReportToolService {


    /**
     * 生成报告
     *
     * @param template
     * @param reportDataModel
     */
    public InputStream genReport(InputStream template, ReportDataModel reportDataModel) throws IOException {
        return new TplWord(template, reportDataModel).toInputStream();
    }

    /**
     * 将报告转为pdf版本
     *
     * @param origin
     * @return
     * @throws IOException
     */
    public byte[] convertToPdf(InputStream origin) throws IOException {
        return new PdfCov(origin).toBytes();
    }

}
